<template>
    <div>
        <h3>添加科室管理</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">科室名称</td>
                    <td><input type="text" v-model="info.Ksname"></td>
                </tr>
                <tr>
                    <td align="right">科室图片</td>
                    <!-- <td><input type="file" @change="imgs">
                    <img :src="info.Ksphoto" width="50" height="50" v-if="info.Ksphoto!=''"></td> -->
                    <td align="right">科室图片</td>
                    <td><input type="file" @change="imgs">
                    <img :src="info.Ksphoto" width="50" height="50" v-if="info.Ksphoto!=''"></td>
                </tr>
                <tr>
                    <td align="right">成立日期</td>
                    <td><input type="date" v-model="info.Cltime"></td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="添加" class="btn btn-success" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted}from 'vue'
import axios from 'axios'; 
import moment from 'moment';
import{useRoute,useRouter}from 'vue-router'
const route=useRoute();
const router=useRouter();

let info:any=reactive({
  "Ksname": "",
  "Ksphoto": "",
  "Cltime": ""
})

const ok=()=>{
    if(info.Ksname==""){
        alert('科室姓名不能为空')
        return
    }
    if(info.Ksphoto==""){
        alert('图片不能为空')
        return
    }
    if(info.Cltime==""){
        alert('时间不能为空')
        return
    }
    axios({
        url:'/api/Yklx/AddKsgl',
        method:'post',
        data:info
    })
    .then((res)=>{
        if(res.data==-1){
            alert("科室名称重复")
            return
        }
        if(res.data>0){
            alert('添加成功')
            router.push('/ksglList')
           
        }
        else
        {
            alert('添加失败');
            return;
        }
    })

}
const imgs=(e:any)=>{
    var obj=e.target.files[0]
    let f=new FormData()
    f.append('file',obj)
    axios({
        url:'/api/File/Img',
        method:'post',
        data:f
    })
    
    
    .then((res)=>{
        if(res.data=="不是图片"){
            alert('不是图片')
            return
        }
        if(res.data=="大于2M")
        {
            alert("大于2M")
            return;
        }
        info.Ksphoto=res.data
    })
}

</script>

<style scoped>

</style>